package internal

import (
	"flag"
	"io/ioutil"
	"path"
	"runtime"
	"template/pkg/cache"
	"template/pkg/config"
	"template/pkg/db"
	"template/pkg/logger"
)

var (
	logPath = flag.String("log", "./log", "the log path")

	TestGFDbConfig = &db.DBConfig{
		Host:  "47.91.108.143",
		Port:  "3306",
		User:  "dev",
		Pass:  "fuGp2rnLwS1yqA==dev",
		Name:  "yuliao",
		Type:  "mysql",
		Debug: true,
	}

	TestRedisConfig = &cache.Config{
		Host:     "127.0.0.1:6379",
		Database: 0,
	}

	projectAddress string
)

func InitConfig() {

	// 获取项目根目录
	_, filename, _, _ := runtime.Caller(0)
	projectAddress = path.Dir(path.Dir(filename))

	// 初始化日志
	logger.InitGLogger(*logPath)
	db.SetGfOrmConfig(TestGFDbConfig)
	cache.SetRedisConfig(TestRedisConfig)
	data, _ := ioutil.ReadFile(projectAddress + "/dev.toml")
	config.InitNacos(data)
}
